using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Dal.S_InvoiceItemTableAdapters;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_InvoiceItem
	{
		private Conn conn = null;
		private static readonly HL_InvoiceItemTableAdapter Adapter = new HL_InvoiceItemTableAdapter();
		public Shop_InvoiceItem()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_InvoiceItem(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetInvoiceByID(int InvoiceID)
		{
			return Shop_InvoiceItem.Adapter.GetInvoiceByID(InvoiceID);
		}
		public DataTable GetInvoiceByOrderFormID(int OrderFormID)
		{
			return this.conn.GetDataTable("SELECT * FROM HLShop_InvoiceItem WHERE (OrderFormID = " + OrderFormID + ")");
		}
		public DataTable GetInvoiceBySalerIDUserNameBegindateEndDate(int SalerID, string UserName, string BeginDate, string EndDate, int InvoiceType)
		{
			return Shop_InvoiceItem.Adapter.GetInvoiceBySalerIDUserNameBegindateEndDate(new int?(SalerID), UserName, BeginDate, EndDate, new int?(InvoiceType));
		}
		public bool DeleteInvoice(string ArrInvoiceID)
		{
			return Shop_InvoiceItem.Adapter.DeleteInvoice(ArrInvoiceID) > 0;
		}
		public bool AddInvoice(int OrderFormID, int UserID, int SalerID, decimal TotalMoney, int InvoiceType, string InvoiceNum, string InvoiceTitle, string IncoiceCaountent, string Drawer, string Inputer, DateTime InvoiceDate)
		{
			S_InvoiceItem.HL_InvoiceItemDataTable hL_InvoiceItemDataTable = new S_InvoiceItem.HL_InvoiceItemDataTable();
			S_InvoiceItem.HL_InvoiceItemRow hL_InvoiceItemRow = hL_InvoiceItemDataTable.NewHL_InvoiceItemRow();
			hL_InvoiceItemRow.OrderFormID = OrderFormID;
			hL_InvoiceItemRow.UserID = UserID;
			hL_InvoiceItemRow.SalerID = SalerID;
			hL_InvoiceItemRow.TotalMoney = TotalMoney;
			hL_InvoiceItemRow.InputTime = DateTime.Now;
			hL_InvoiceItemRow.InvoiceType = InvoiceType;
			hL_InvoiceItemRow.InvoiceNum = InvoiceNum;
			hL_InvoiceItemRow.InvoiceTitle = InvoiceTitle;
			hL_InvoiceItemRow.InvoiceContent = IncoiceCaountent;
			hL_InvoiceItemRow.Drawer = Drawer;
			hL_InvoiceItemRow.Inputer = Inputer;
			hL_InvoiceItemRow.InvoiceDate = InvoiceDate;
			hL_InvoiceItemDataTable.AddHL_InvoiceItemRow(hL_InvoiceItemRow);
			return Shop_InvoiceItem.Adapter.Update(hL_InvoiceItemDataTable) == 1 && this.conn.Execute("Update HLShop_Order Set Invoiced=0 Where OrderFormID=" + OrderFormID) == 1;
		}
		public bool AddSalerInvoice(int OrderFormID, int UserID, int SalerID, decimal TotalMoney, int InvoiceType, string InvoiceNum, string InvoiceTitle, string IncoiceCaountent, string Drawer, string Inputer, DateTime InvoiceDate)
		{
			S_InvoiceItem.HL_InvoiceItemDataTable hL_InvoiceItemDataTable = new S_InvoiceItem.HL_InvoiceItemDataTable();
			S_InvoiceItem.HL_InvoiceItemRow hL_InvoiceItemRow = hL_InvoiceItemDataTable.NewHL_InvoiceItemRow();
			hL_InvoiceItemRow.OrderFormID = OrderFormID;
			hL_InvoiceItemRow.UserID = UserID;
			hL_InvoiceItemRow.SalerID = SalerID;
			hL_InvoiceItemRow.TotalMoney = TotalMoney;
			hL_InvoiceItemRow.InputTime = DateTime.Now;
			hL_InvoiceItemRow.InvoiceType = InvoiceType;
			hL_InvoiceItemRow.InvoiceNum = InvoiceNum;
			hL_InvoiceItemRow.InvoiceTitle = InvoiceTitle;
			hL_InvoiceItemRow.InvoiceContent = IncoiceCaountent;
			hL_InvoiceItemRow.Drawer = Drawer;
			hL_InvoiceItemRow.Inputer = Inputer;
			hL_InvoiceItemRow.InvoiceDate = InvoiceDate;
			hL_InvoiceItemDataTable.AddHL_InvoiceItemRow(hL_InvoiceItemRow);
			return Shop_InvoiceItem.Adapter.Update(hL_InvoiceItemDataTable) == 1 && this.conn.Execute("Update HLShop_Order Set Invoiced=1 Where OrderFormID=" + OrderFormID) == 1;
		}
		public bool UpdateInvoice(string inputer, int InvoiceType, string InvoiceNum, string InvoiceTitle, string IncoiceCaountent, string Drawer, DateTime InvoiceDate, int InvoiceID)
		{
			S_InvoiceItem.HL_InvoiceItemDataTable invoiceByID = Shop_InvoiceItem.Adapter.GetInvoiceByID(InvoiceID);
			bool result;
			if (invoiceByID.Rows.Count == 0)
			{
				result = false;
			}
			else
			{
				S_InvoiceItem.HL_InvoiceItemRow hL_InvoiceItemRow = invoiceByID[0];
				hL_InvoiceItemRow.InvoiceType = InvoiceType;
				hL_InvoiceItemRow.InvoiceNum = InvoiceNum;
				hL_InvoiceItemRow.InvoiceTitle = InvoiceTitle;
				hL_InvoiceItemRow.InvoiceContent = IncoiceCaountent;
				hL_InvoiceItemRow.Drawer = Drawer;
				hL_InvoiceItemRow.Inputer = inputer;
				hL_InvoiceItemRow.InvoiceDate = InvoiceDate;
				result = (Shop_InvoiceItem.Adapter.Update(hL_InvoiceItemRow) == 1);
			}
			return result;
		}
	}
}
